from Defaults import Mode

__author__ = 'deadmoroz'

BACKSLASH_ESCAPE = Mode({"begin": "\\\\.", "relevance": 0})
NUMBER_RE = "\\b\\d+(\\.\\d+)?"
ID_RE = "[a-zA-Z][a-zA-Z0-9_]*"
C_NUMBER_RE = "\\b(0x[A-Za-z0-9]+|\\d+(\\.\\d+)?)"

class ModeNotFound(Exception):
    pass


class Registry(object):
    _modes = {
        "BACKSLASH_ESCAPE": BACKSLASH_ESCAPE,
        "APOS_STRING_MODE": Mode({
            "className": "string",
            "begin": "\\'", "end": "\\'",
            "illegal": "\\n",
            "contains": [BACKSLASH_ESCAPE],
            "relevance": 0
        }),
        "QUOTE_STRING_MODE": Mode({
            "className": "string",
            "begin": "\"",
            "end": "\"",
            "illegal": "\\n",
            "contains": [BACKSLASH_ESCAPE],
            "relevance": 0
        }),
        "NUMBER_MODE": Mode({
            "className": "number",
            "begin": NUMBER_RE,
            "relevance": 0
        }),
        "C_LINE_COMMENT_MODE": Mode({
            "className": "comment",
            "begin": "//", "end": "$"
        }),
        "C_BLOCK_COMMENT_MODE": Mode({
            "className": "comment",
            "begin": "/\\*", "end": "\\*/"
        }),
        "C_NUMBER_MODE": Mode({
            "className": "number",
            "begin": C_NUMBER_RE,
            "relevance": 0
        }),
        "HASH_COMMENT_MODE": Mode({
            "className": "comment",
            "begin": "#", "end": "$"
        })
    }

    def __getitem__(self, item):
        if item in Registry._modes:
            return Registry._modes[item]
        raise ModeNotFound()
